//
//  ViewController.swift
//  JWTextPickerManager
//
//  Created by linjw on 09/27/2022.
//  Copyright (c) 2022 linjw. All rights reserved.
//

import UIKit
import JWTextPickerManager
import RxSwift
import RxCocoa

class ViewController: UIViewController {
    
    private lazy var disposeBag = DisposeBag()
    
    lazy var menuTitles: [String] = ["普通弹窗"]
    
    @IBOutlet weak var listView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        listView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
        
        listView.dataSource = self
        listView.delegate = self
        
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}

extension ViewController: UITableViewDataSource, UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return menuTitles.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let item = menuTitles[indexPath.row]
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
        cell.textLabel?.text = item
        cell.selectionStyle = .none
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let item = menuTitles[indexPath.row]
        debugPrint("点击了: \(item)")
        
        let style = JWTextPickerViewConfig.defaultConfig()
        style.cancelTextColor = UIColor(red: 0.53, green: 0.53, blue: 0.58, alpha: 1)
        style.submitTextColor = UIColor(red: 0.32, green: 0.91, blue: 0.8, alpha: 1)
        style.headViewCornerRadius = 24.0
        JWTextPickerManager.rx.showCombinePicker(list: allUserWeightList(),
                                                type: JWTextPickerColumnsType.one,
                                                title: "请选择",
                                                selectedType: JWTextPickerSelectedType.index(first: 0, second: 0, third: 0),
                                                styleConfig: style)
        .map {
            let chooseItems = $0
        }
        .subscribe().disposed(by: disposeBag)
    }
    
    func allUserWeightList() -> [PickerTextModel] {
        
        return (30...160).map {
            let model = PickerTextModel()
            model.pickerId = "\($0)"
            model.pickerText = "\($0)kg"
            return model
        }
        
    }
    
}
